home *** CD-ROM | disk | FTP | other *** search
/ AppleScript - The Beta Release / AppleScript - The Beta Release.iso / Documentation / develop / Apple Event Objects and You / Apple Event Objects (code) / Interaction.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-08  |  2.6 KB  |  91 lines  |  [TEXT/KAHL]

  1. /* Interaction.c */
  2.  
  3. /* This file demonstrates the techniques necesary for interacting with the user */
  4. /* when you receive an Apple event.                                             */
  5.  
  6. #include "ScriptScrap.h"
  7. #include "Prototypes.h"
  8.  
  9. /* Prototype declaration for a local routine */
  10. static pascal Boolean    MyIdleProc(EventRecord *theEvent, long *sleep, RgnHandle *mouseRgn);
  11.  
  12. OSErr MyInteractWithUser(Boolean isUrgent)
  13. {
  14.     NMRec        notice;
  15.     Handle        mySmallIcon;
  16.     Handle        notificationString;
  17.     SignedByte    sicnState, strState;
  18.     OSErr        err = noErr;
  19.     
  20.     if (!gInFront) {
  21.         /* Set up a notification which blinks a small icon and (optionally) */
  22.         /* shows a dialog to the user. */
  23.         mySmallIcon = Get1Resource('SICN', 128);
  24.         sicnState = HGetState(mySmallIcon);
  25.         HNoPurge(mySmallIcon);
  26.         notificationString = (Handle)GetString(3001);
  27.         strState = HGetState(notificationString);
  28.         MoveHHi(notificationString);
  29.         HLock(notificationString);
  30.         
  31.         notice.qType = nmType;
  32.         notice.nmMark = 1;
  33.         notice.nmIcon = mySmallIcon;
  34.         notice.nmSound = 0L;
  35.         if (isUrgent) 
  36.             notice.nmStr = (StringPtr)*notificationString;
  37.         else
  38.             notice.nmStr = 0L;
  39.         notice.nmResp = 0L;
  40.         notice.nmRefCon = 0L;
  41.         
  42.         /* If we're in the background, the next call will either switch us to the front, */
  43.         /* call the Notification Manager, or return an error indicating that user interaction */
  44.         /* is not allowed. */
  45.         /* If interaction is allowed (and we're in the back), this call will wait for our */
  46.         /* application to become frontmost and then return noErr. */
  47.         /* If we're already in front, it returns noErr. */
  48.         err = AEInteractWithUser(kAEDefaultTimeout, (NMRecPtr)¬ice, (IdleProcPtr)MyIdleProc);
  49.         HSetState(mySmallIcon, sicnState);
  50.         HSetState(notificationString, strState);
  51.     }
  52.     return err;
  53. } /* MyInteractWithUser */
  54.  
  55.  
  56. /* MyIdleProc
  57. **
  58. ** This routine gets either an updateEvt, an activateEvt, a nullEvent or an
  59. ** OSEvent.  The first time called it will get a nullEvent; this is its chance
  60. ** to set the sleep value and mouseRegion that will be passed to WaitNextEvent
  61. ** by the caller within the AEM.  After that it will also get events of the
  62. ** other types (which are lost if masked out by the AEM) and must do with them
  63. ** whatever is appropriate.
  64. */
  65.  
  66. static pascal Boolean    MyIdleProc(EventRecord *theEvent, long *sleep, RgnHandle *mouseRgn)
  67. {
  68.     switch (theEvent->what) {
  69.  
  70.         case updateEvt:
  71.             DoUpdate((WindowPtr)theEvent->message);
  72.         break;
  73.         
  74.         case activateEvt:
  75.             DoActivate((WindowPtr)theEvent->message, theEvent->modifiers & 1);
  76.         break;
  77.             
  78.         case app4Evt:
  79.         break;
  80.  
  81.         case nullEvent:
  82.             *mouseRgn = NULL;
  83.             *sleep    = 600L;    /* 10 seconds */
  84.             break;
  85.     }
  86.     return(false);
  87. }
  88.  
  89.  
  90.  
  91.